//============================================================================================
/**
 * @file	bag_obj.c
 * @brief	バッグ画面OBJ処理
 * @author	Hiroyuki Nakamura
 * @date	05.10.31
 */
//============================================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/gamedata.h"
#include "system/procsys.h"
#include "system/fontproc.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/pm_str.h"
#include "system/lib_pack.h"
#include "system/snd_tool.h"
#include "system/arc_tool.h"
#include "system/arc_util.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/render_oam.h"
#include "system/brightness.h"
#include "system/buflen.h"
#include "system/msgdata.h"
#include "system/wordset.h"
#include "system/numfont.h"
#include "savedata/config.h"
#include "itemtool/item.h"
#include "battle/wazatype_icon.h"
#include "battle/battle_common.h"
#include "poketool/waza_tool.h"
#include "../../field/shop_gra.naix"

#define	BAG_OBJ_H_GLOBAL
#include "application/bag.h"
#include "bag_main.h"
#include "bag_obj.h"
#include "bag_gra.naix"


//============================================================================================
//	定数定義
//============================================================================================
enum {
	PCMV_SEQ_WAIT = 0,
	PCMV_SEQ_MOVE,
};

#define	BMP_P_ICON_PX	( 0 )
#define	BMP_P_ICON_PY	( 11 )
#define	BMP_P_ICON_SX	( 12 )
#define	BMP_P_ICON_SY	( 2 )


#define	CLACT_ID_COMMON		( 49401 )	// この画面で使用するセルアクターのID

// キャラリソースID
enum {
	CHR_ID_CHGCURSOR = CLACT_ID_COMMON,	// 入れ替えカーソル
	CHR_ID_POKEARROW,					// ポケット移動矢印
	CHR_ID_SUBPANEL,					// サブパネル
	CHR_ID_ITEMICON0,					// アイテムアイコン
	CHR_ID_ITEMICON1,					// アイテムアイコン
	CHR_ID_ITEMICON2,					// アイテムアイコン
	CHR_ID_ITEMICON3,					// アイテムアイコン
	CHR_ID_ITEMICON4,					// アイテムアイコン
	CHR_ID_ITEMICON5,					// アイテムアイコン
	CHR_ID_NUMARROW,					// 個数選択矢印
	CHR_ID_TYPEICON,					// タイプアイコン
	CHR_ID_KINDICON,					// 分類アイコン

	CHR_ID_MAX = CHR_ID_KINDICON - CLACT_ID_COMMON + 1
};
// パレットリソースID
enum {
	PAL_ID_CURSOR = CLACT_ID_COMMON,	// カーソル関連
	PAL_ID_SUBPANEL,					// サブパネル
	PAL_ID_ITEMICON0,					// アイテムアイコン
	PAL_ID_ITEMICON1,					// アイテムアイコン
	PAL_ID_ITEMICON2,					// アイテムアイコン
	PAL_ID_ITEMICON3,					// アイテムアイコン
	PAL_ID_ITEMICON4,					// アイテムアイコン
	PAL_ID_ITEMICON5,					// アイテムアイコン
	PAL_ID_NUMARROW,					// 個数選択矢印
	PAL_ID_TYPEICON,					// タイプアイコン

	PAL_ID_MAX = PAL_ID_TYPEICON - CLACT_ID_COMMON + 1
};
// セルリソースID
enum {
	CEL_ID_CHGCURSOR = CLACT_ID_COMMON,	// 入れ替えカーソル
	CEL_ID_POKEARROW,					// ポケット移動矢印
	CEL_ID_BUTTONEFF,					// ボタンエフェクト
	CEL_ID_ITEMICON,					// アイテムアイコン
	CEL_ID_NUMARROW,					// 個数選択矢印
	CEL_ID_TYPEICON,					// タイプアイコン

	CEL_ID_MAX = CEL_ID_TYPEICON - CLACT_ID_COMMON + 1
};
// セルアニメリソースID
enum {
	ANM_ID_SELCURSOR = CLACT_ID_COMMON,	// アイテム選択カーソル
	ANM_ID_CHGCURSOR,					// 入れ替えカーソル
	ANM_ID_POKEARROW,					// ポケット移動矢印
	ANM_ID_BUTTONEFF,					// ボタンエフェクト
	ANM_ID_ITEMICON,					// アイテムアイコン
	ANM_ID_NUMARROW,					// 個数選択矢印
	ANM_ID_TYPEICON,					// タイプアイコン

	ANM_ID_MAX = ANM_ID_TYPEICON - CLACT_ID_COMMON + 1
};

#define	NUM_ARROW_DEL_UX	( 220 )		// 個数選択上矢印X座標（捨てる）
#define	NUM_ARROW_DEL_UY	( 156 )		// 個数選択上矢印Y座標（捨てる）
#define	NUM_ARROW_DEL_DX	( 220 )		// 個数選択下矢印X座標（捨てる）
#define	NUM_ARROW_DEL_DY	( 180 )		// 個数選択下矢印Y座標（捨てる）
#define	NUM_ARROW_SALE_UX	( 162 )		// 個数選択上矢印X座標（売る）
#define	NUM_ARROW_SALE_UY	( 108 )		// 個数選択上矢印Y座標（売る）
#define	NUM_ARROW_SALE_DX	( 162 )		// 個数選択下矢印X座標（売る）
#define	NUM_ARROW_SALE_DY	( 132 )		// 個数選択下矢印Y座標（売る）


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
static void BAGOBJ_ClactResManInit( BAG_WORK * wk );
static void BAGOBJ_ClactGraphicLoad( BAG_WORK * wk );
static void BAGOBJ_ClactAdd( BAG_WORK * wk );

static u8 PocketCursorObjPXGet( BAG_WORK * wk, u8 poke );
static void PocketCursorMove( BAG_WORK * wk );
static void _page_button_on_func( BAG_WORK *wk );


//============================================================================================
//	グローバル変数
//============================================================================================
// セルアクターデータ
static const TCATS_OBJECT_ADD_PARAM_S ClactParamTbl[] =
{
	{	// アイテム入れ替えカーソル
		177, 14, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_CHGCURSOR, PAL_ID_CURSOR, CEL_ID_CHGCURSOR, ANM_ID_CHGCURSOR, 0, 0 },
		1, 0
	},
	{	// アイテムアイコン1
		22,59, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_ITEMICON0, PAL_ID_ITEMICON0, CEL_ID_ITEMICON, ANM_ID_ITEMICON, 0, 0 },
		1, 0
	},
	{	// アイテムアイコン2
		152,59, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_ITEMICON1, PAL_ID_ITEMICON1, CEL_ID_ITEMICON, ANM_ID_ITEMICON, 0, 0 },
		1, 0
	},
	{	// アイテムアイコン3
		22,100, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_ITEMICON2, PAL_ID_ITEMICON2, CEL_ID_ITEMICON, ANM_ID_ITEMICON, 0, 0 },
		1, 0
	},
	{	// アイテムアイコン4
		152,100, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_ITEMICON3, PAL_ID_ITEMICON3, CEL_ID_ITEMICON, ANM_ID_ITEMICON, 0, 0 },
		1, 0
	},
	{	// アイテムアイコン5
		22,139, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_ITEMICON4, PAL_ID_ITEMICON4, CEL_ID_ITEMICON, ANM_ID_ITEMICON, 0, 0 },
		1, 0
	},
	{	// アイテムアイコン6
		152,139, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_ITEMICON5, PAL_ID_ITEMICON5, CEL_ID_ITEMICON, ANM_ID_ITEMICON, 0, 0 },
		1, 0
	},
	{	// タイプアイコン(10)
		48, 112, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_TYPEICON, PAL_ID_TYPEICON, CEL_ID_TYPEICON, ANM_ID_TYPEICON, 0, 0 },
		0, 0
	},
	{	// 分類アイコン
		168-32, 112, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_KINDICON, PAL_ID_TYPEICON, CEL_ID_TYPEICON, ANM_ID_TYPEICON, 0, 0 },
		0, 0
	},


	// 12
	{	// サブパネル用ボタン１
		16+32*0, 16, 0,
		0, 1, 0, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用ボタン２
		16+32*1, 16, 0,
		1, 1, 1, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用ボタン３
		16+32*2, 16, 0,
		2, 1, 2, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用ボタン４
		16+32*3, 16, 0,
		3, 1, 3, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用ボタン５
		16+32*4, 16, 0,
		4, 1, 4, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用ボタン６
		16+32*5, 16, 0,
		5, 1, 5, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用ボタン７
		16+32*6, 16, 0,
		6, 1, 6, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用ボタン８
		16+32*7, 16, 0,
		7, 1, 7, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},

	{	// サブパネル用上ボタン
		8*3, 176, 0,
		12, 1, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用下ボタン
		40+8*3, 176, 0,
		13, 1, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用やめるボタン
		224, 176, 0,
		16, 1, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用カーソル	23
		16, 16, 0,
		8, 0, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		1, 0
	},

	{	// サブパネル用どうぐさしこみカーソル１
		16, 6*8, 0,
		19, 1, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		1, 0
	},
	{	// サブパネル用どうぐさしこみカーソル２
		144, 6*8, 0,
		19, 1, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		1, 0
	},
	{	// サブパネル用どうぐさしこみカーソル３
		16, 11*8, 0,
		19, 1, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		1, 0
	},
	{	// サブパネル用どうぐさしこみカーソル４
		144, 11*8, 0,
		19, 1, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		1, 0
	},
	{	// サブパネル用どうぐさしこみカーソル５
		16, 16*8, 0,
		19, 1, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		1, 0
	},
	{	// サブパネル用どうぐさしこみカーソル６
		144, 16*8, 0,
		19, 1, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		1, 0
	},

	{	// サブパネル用どうぐ差し込みカーソル
		16, 6*8, 0,
		20, 0, 9, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},

	{	// サブパネル用道具使用時選択肢０
		48, 144, 0,
		22, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用道具使用時選択肢１
		48+12*8, 144, 0,
		22, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用道具使用時選択肢２
		48, 176, 0,
		22, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// サブパネル用道具使用時選択肢３
		48+12*8, 176, 0,
		22, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},


	{	// 売る・捨てる時の上矢印パネル0
		136, 104, 0,
		25, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// 売る・捨てる時の上矢印パネル1
		136+32, 104, 0,
		25, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// 売る・捨てる時の上矢印パネル2
		136+64, 104, 0,
		25, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// 売る・捨てる時の下矢印パネル0
		136, 152, 0,
		27, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// 売る・捨てる時の下矢印パネル1
		136+32, 152, 0,
		27, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
	{	// 売る・捨てる時の下矢印パネル2
		136+64, 152, 0,
		27, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},

	{	// 「捨てる」「売る」ボタン
		160, 192-16, 0,
		31, 0, 8, NNS_G2D_VRAM_TYPE_2DSUB,
		{ CHR_ID_SUBPANEL, PAL_ID_SUBPANEL, CEL_ID_BUTTONEFF, ANM_ID_BUTTONEFF, 0, 0 },
		0, 0
	},
};



//--------------------------------------------------------------------------------------------
/**
 * @brief	セルアクター初期化
 *
 * @param	wk		バッグ画面のワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void BagCellActorInit( BAG_WORK * wk )
{
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// MAIN DISP OBJ ON
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// SUB DISP OBJ ON

	initVramTransferManagerHeap( 32, HEAPID_BAG );

	BAGOBJ_ClactResManInit( wk );
	BAGOBJ_ClactGraphicLoad( wk );
	BAGOBJ_ClactAdd( wk );

	{
		CLACT_U_EASYRENDER_DATA *renddata = CATS_EasyRenderGet( wk->csp );
		CLACT_U_SetSubSurfaceMatrix( renddata, 0, BAG_SUB_ACTOR_DISTANCE );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * @brief	セルアクター解放
 *
 * @param	wk		バッグ画面のワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void BAGOBJ_ClactFree( BAG_WORK * wk )
{
	u32	i;

	for( i=0; i<BAG_ACT_MAX; i++ ){
		CATS_ActorPointerDelete_S( wk->cap[i] );
	}
	CATS_ResourceDestructor_S( wk->csp, wk->crp );
	CATS_FreeMemory( wk->csp );

	sys_FreeMemoryEz( wk->objPalData );
}

//--------------------------------------------------------------------------------------------
/**
 * @brief	アニメ
 *
 * @param	wk		バッグ画面のワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void Bag_ObjAnmMain( BAG_WORK * wk )
{
	u32	i;

	for( i=0; i<BAG_ACT_MAX; i++ ){
		CATS_ObjectUpdateCap( wk->cap[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * @brief	アイテムアイコン変更
 *
 * @param	wk		バッグ画面のワーク
 * @param	item	アイテム番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void BagItemIconChange( BAG_WORK * wk, int pos, u16 item )
{
	CATS_ChangeResourceCharArc(
		wk->csp, wk->crp,
		ARC_ITEMICON, GetItemIndex( item, ITEM_GET_ICON_CGX ), 0, CHR_ID_ITEMICON0+pos );
	CATS_ChangeResourcePlttArc(
		wk->csp, wk->crp,
		ARC_ITEMICON, GetItemIndex( item, ITEM_GET_ICON_PAL ), 0, PAL_ID_ITEMICON0+pos );
}


//============================================================================================
//	ポケットカーソル
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * @brief	ポケットカーソル動作チェック
 *
 * @param	wk		バッグ画面のワーク
 *
 * @retval	"TRUE = 停止中"
 * @retval	"FALSE = 動作中"
 */
//--------------------------------------------------------------------------------------------
u8 BagPocketCursorMoveCheck( BAG_WORK * wk )
{
	if( wk->pcmv.req == PCMV_SEQ_WAIT ){
		return TRUE;
	}
	return FALSE;
}

//--------------------------------------------------------------------------------------------
/**
 * @brief	ポケットカーソル動作初期化
 *
 * @param	wk		バッグ画面のワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void BagPocketCursorMoveInit( BAG_WORK * wk )
{
	wk->pcmv.cnt  = 0;
	wk->pcmv.req  = PCMV_SEQ_MOVE;
}

//--------------------------------------------------------------------------------------------
/**
 * @brief	ポケットカーソル動作メイン
 *
 * @param	wk		バッグ画面のワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void BagPocketCursorMoveMain( BAG_WORK * wk )
{
	switch( wk->pcmv.req ){
	case PCMV_SEQ_WAIT:
		break;
	case PCMV_SEQ_MOVE:
		PocketCursorMove( wk );
		break;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * @brief	技マシンのアイコンセット
 *
 * @param	wk		バッグ画面のワーク
 * @param	item	アイテム番号
 * @param	flg		表示フラグ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void BagObj_WazaIconPut( BAG_WORK * wk, u16 item, u8 flg )
{
	u16	waza;
	u16	type;
	u16	kind;

	CATS_ObjectEnableCap( wk->cap[ ACT_TYPE ], flg );
	CATS_ObjectEnableCap( wk->cap[ ACT_KIND ], flg );

	if( flg == ACT_OFF ){ return; }

	waza = GetWazaNoItem( item );
	type = WT_WazaDataParaGet( waza, ID_WTD_wazatype );
	kind = WT_WazaDataParaGet( waza, ID_WTD_kind );

	CATS_ChangeResourceCharArc(
		wk->csp, wk->crp, WazaTypeIcon_ArcIDGet(),
		WazaTypeIcon_CgrIDGet(type), WAZATYPEICON_COMP_CHAR, CHR_ID_TYPEICON );
	CATS_ObjectPaletteSetCap( wk->cap[ACT_TYPE], WazaTypeIcon_PlttOffsetGet(type)+4 );

	CATS_ChangeResourceCharArc(
		wk->csp, wk->crp, WazaKindIcon_ArcIDGet(),
		WazaKindIcon_CgrIDGet(kind), WAZAKINDICON_COMP_CHAR, CHR_ID_KINDICON );
	CATS_ObjectPaletteSetCap( wk->cap[ACT_KIND], WazaKindIcon_PlttOffsetGet(kind)+4 );
}

//--------------------------------------------------------------------------------------------
/**
 * リソースマネージャー初期化
 *
 * @param	wk		バッグ画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BAGOBJ_ClactResManInit( BAG_WORK * wk )
{
	TCATS_RESOURCE_NUM_LIST	crnl = { CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0, 0 };

	wk->csp = CATS_AllocMemory( HEAPID_BAG );
	wk->crp = CATS_ResourceCreate( wk->csp );
	{
		TCATS_OAM_INIT	coi = {
			0, 128,
			0, 32,
			0, 128,
			0, 32,
		};
		TCATS_CHAR_MANAGER_MAKE ccmm = {
			BAG_ACT_MAX,
			1024*128,
			1024*16,
			GX_OBJVRAMMODE_CHAR_1D_32K,
			GX_OBJVRAMMODE_CHAR_1D_32K
		};
		CATS_SystemInit( wk->csp, &coi, &ccmm, 32 );
	}
	CATS_ClactSetInit( wk->csp, wk->crp, BAG_ACT_MAX );
	CATS_ResourceManagerInit( wk->csp, wk->crp, &crnl );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターのグラフィックロード
 *
 * @param	wk		バッグ画面のワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BAGOBJ_ClactGraphicLoad( BAG_WORK * wk )
{
	u32	chr, pal;

	if( wk->sex == 0 ){
		chr = NARC_bag_gra_bag_01_NCGR;
		pal = NARC_bag_gra_bag_01_NCLR;
	}else{
		chr = NARC_bag_gra_bag_02_NCGR;
		pal = NARC_bag_gra_bag_02_NCLR;
	}

	// キャラ
	// 入れ替えカーソル
	CATS_LoadResourceCharArc(
		wk->csp, wk->crp, ARC_BAG_GRA,
		NARC_bag_gra_bag_selcur2_NCGR, 0, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_CHGCURSOR );
	// ポケット移動矢印
	CATS_LoadResourceCharArc(
		wk->csp, wk->crp, ARC_BAG_GRA,
		NARC_bag_gra_bag_arrow_NCGR, 0, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_POKEARROW );

	// サブパネル
	CATS_LoadResourceCharArc(
		wk->csp, wk->crp, ARC_BAG_GRA,
		NARC_bag_gra_itemOBJ_d_ncgr, 0, NNS_G2D_VRAM_TYPE_2DSUB, CHR_ID_SUBPANEL );

	// 個数選択矢印
	CATS_LoadResourceCharArc(
		wk->csp, wk->crp, ARC_SHOP_GRA,
		NARC_shop_gra_shop_arw_NCGR, 0, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_NUMARROW );
	// アイテムアイコン
	{
		int i;
		for(i=0;i<BAG_PAGE_ITEM_NUM;i++){
			CATS_LoadResourceCharArc(
				wk->csp, wk->crp, ARC_ITEMICON,
				GetItemIndex(0,ITEM_GET_ICON_CGX), 0, NNS_G2D_VRAM_TYPE_2DSUB, CHR_ID_ITEMICON0+i );
		}
	}
	// タイプアイコン
	WazaTypeIcon_CharResourceLoad( wk->csp, wk->crp, NNS_G2D_VRAM_TYPE_2DMAIN, 0, CHR_ID_TYPEICON );
	// 分類アイコン
	WazaKindIcon_CharResourceLoad( wk->csp, wk->crp, NNS_G2D_VRAM_TYPE_2DMAIN, 0, CHR_ID_KINDICON );

	// パレット
	// カーソル関連
	CATS_LoadResourcePlttArc(
		wk->csp, wk->crp, ARC_BAG_GRA,
		NARC_bag_gra_bag_cursor_NCLR, 0, 2, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_CURSOR );
	// 個数選択矢印
	CATS_LoadResourcePlttArc(
		wk->csp, wk->crp, ARC_SHOP_GRA,
		NARC_shop_gra_shop_obj_NCLR, 0, 2, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_NUMARROW );
	// タイプアイコン
	WazaTypeIcon_PlttResourceLoad( wk->csp, wk->crp, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_TYPEICON );

	CATS_LoadResourcePlttArc(
		wk->csp, wk->crp, ARC_BAG_GRA,
		NARC_bag_gra_itemOBJ01_d_nclr, 0, 10, NNS_G2D_VRAM_TYPE_2DSUB, PAL_ID_SUBPANEL );
	// アイテムアイコン
	{
		int i;
		for(i=0;i<BAG_PAGE_ITEM_NUM;i++){
			CATS_LoadResourcePlttArc(
				wk->csp, wk->crp, ARC_ITEMICON,
				GetItemIndex(0,ITEM_GET_ICON_PAL), 0, 1, NNS_G2D_VRAM_TYPE_2DSUB, PAL_ID_ITEMICON0+i );
		}
	}

	// セル
	// 入れ替えカーソル
	CATS_LoadResourceCellArc(
		wk->csp, wk->crp, ARC_BAG_GRA, NARC_bag_gra_bag_selcur2_NCER, 0, CEL_ID_CHGCURSOR );
	// ポケット移動矢印
	CATS_LoadResourceCellArc(
		wk->csp, wk->crp, ARC_BAG_GRA, NARC_bag_gra_bag_arrow_NCER, 0, CEL_ID_POKEARROW );
	// サブパネル用セルデータ
	CATS_LoadResourceCellArc(
		wk->csp, wk->crp, ARC_BAG_GRA, NARC_bag_gra_itemOBJ_d_ncer, 0, CEL_ID_BUTTONEFF );
	// アイテムアイコン
	CATS_LoadResourceCellArc(
		wk->csp, wk->crp, ARC_ITEMICON, ItemIconCellGet(), 0, CEL_ID_ITEMICON );
	// 個数選択矢印
	CATS_LoadResourceCellArc(
		wk->csp, wk->crp, ARC_SHOP_GRA, NARC_shop_gra_shop_arw_NCER, 0, CEL_ID_NUMARROW );

	// セルアニメ
	// アイテム選択カーソル
	CATS_LoadResourceCellAnmArc(
		wk->csp, wk->crp, ARC_BAG_GRA, NARC_bag_gra_bag_selcur_NANR, 0, ANM_ID_SELCURSOR );
	// 入れ替えカーソル
	CATS_LoadResourceCellAnmArc(
		wk->csp, wk->crp, ARC_BAG_GRA, NARC_bag_gra_bag_selcur2_NANR, 0, ANM_ID_CHGCURSOR );
	// ポケット移動矢印
	CATS_LoadResourceCellAnmArc(
		wk->csp, wk->crp, ARC_BAG_GRA, NARC_bag_gra_bag_arrow_NANR, 0, ANM_ID_POKEARROW );
	// サブパネル用アニメ
	CATS_LoadResourceCellAnmArc(
		wk->csp, wk->crp, ARC_BAG_GRA, NARC_bag_gra_itemOBJ_d_nanr, 0, ANM_ID_BUTTONEFF );
	// アイテムアイコン
	CATS_LoadResourceCellAnmArc(
		wk->csp, wk->crp, ARC_ITEMICON, ItemIconCAnmGet(), 0, ANM_ID_ITEMICON );
	// 個数選択矢印
	CATS_LoadResourceCellAnmArc(
		wk->csp, wk->crp, ARC_SHOP_GRA, NARC_shop_gra_shop_arw_NANR, 0, ANM_ID_NUMARROW );

	// タイプアイコンのセルとアニメ
	WazaTypeIcon_CellAnmResourceLoad( wk->csp, wk->crp, CEL_ID_TYPEICON, ANM_ID_TYPEICON );

	// 後から転送に使うポケットアイコン用のパレットデータを読み込む
	wk->objPalData = ArcUtil_PalDataGet( ARC_BAG_GRA, NARC_bag_gra_itemOBJ02_d_nclr, &wk->objPalPtr, HEAPID_BAG );
}

#define BAG_SELECT_PLATE_NUM	( 4 )

//--------------------------------------------------------------------------------------------
/**
 * バッグ画面のセルアクターをセット
 *
 * @param	wk		バッグ画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BAGOBJ_ClactAdd( BAG_WORK * wk )
{
	u32	i;

	for( i=0; i<BAG_ACT_MAX; i++ ){
		wk->cap[i] = CATS_ObjectAdd_S_SubDistance( wk->csp, wk->crp, &ClactParamTbl[i], BAG_SUB_ACTOR_DISTANCE );
//		wk->cap[i] = CATS_ObjectAdd_S( wk->csp, wk->crp, &ClactParamTbl[i] );
		OS_Printf("bag obj %d = ok \n",i);
	}

	// やめるボタンのプライオリティを0面よりは下に
	CATS_ObjectBGPriSetCap( wk->cap[ACT_BAG_BACK_BUTTON], 1);

	// どうぐ選択時の選択肢も下に
	for(i=0;i<BAG_SELECT_PLATE_NUM;i++){
		CATS_ObjectBGPriSetCap( wk->cap[ACT_BAG_SELECT_PLATE0+i], 1);
	}

	// ポケット選択ボタンも下に
	for(i=0;i<8;i++){
		CATS_ObjectBGPriSetCap( wk->cap[ACT_BAG_BUTTON_1+i], 1);
	}

	// ポケットボタンの表示ON/OFF
	BagObj_PocketSelectButtonOnOff( wk, ACT_ON );

	// を隠す
	CATS_ObjectEnableCap( wk->cap[ ACT_LIST_SEL_CHANGE ], ACT_OFF );
//	CATS_ObjectEnableCap( wk->cap[ ACT_BUTTON_ANM ], ACT_OFF );

	// ポケモンのタイプアイコンを隠す
	CATS_ObjectEnableCap( wk->cap[ ACT_TYPE ], ACT_OFF );
	CATS_ObjectEnableCap( wk->cap[ ACT_KIND ], ACT_OFF );

	// どうぐを選択した時の選択肢を隠す
	for(i=0;i<BAG_SELECT_PLATE_NUM;i++){
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_SELECT_PLATE0+i ], ACT_OFF );

	}

	// 売る・捨てるの数字選択用ボタンを隠す
	for(i=0;i<BAG_ITEM_COUNT_BUTTON_NUM;i++){
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_NUM_UP0+i ], ACT_OFF );
	}

	// 「売る」「捨てる」ボタンを隠す
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_BUTTON_SELL_DOPOSIT ], ACT_OFF );
	CATS_ObjectBGPriSetCap( wk->cap[ACT_BAG_BUTTON_SELL_DOPOSIT], 1);
}


//--------------------------------------------------------------------------------------------
/**
 * ポケットカーソル動作
 *
 * @param	wk		バッグ画面のワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PocketCursorMove( BAG_WORK * wk )
{
	VecFx32 vec;

	wk->pcmv.req = PCMV_SEQ_WAIT;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケットカーソルOBJのX座標
 *
 * @param	wk		バッグ画面のワーク
 * @param	poke	ポケット番号
 *
 * @return	カーソルOBJのX座標
 *
 * @li	ポケット番号からカーソル位置を取得する
 */
//--------------------------------------------------------------------------------------------
static u8 PocketCursorObjPXGet( BAG_WORK * wk, u8 poke )
{
	return BMP_P_ICON_PX * 8 + wk->p_icon_gx + wk->p_icon_sx * poke + P_ICON_DEF_PX;
}


// カーソルデータ
typedef struct{
	u8 x,y;
	u8 anim;
	u8 pal;
}BAG_CURSOR_INFO;

// 通常
static const BAG_CURSOR_INFO bag_cursor_tbl[]={
	{16+32*0,16,8,9,},		// 上の８つ
	{16+32*1,16,8,9,},
	{16+32*2,16,8,9,},
	{16+32*3,16,8,9,},
	{16+32*4,16,8,9,},
	{16+32*5,16,8,9,},
	{16+32*6,16,8,9,},
	{16+32*7,16,8,9,},

	{48,    56,     10,9,},	// 真ん中の６つ			// 8
	{48+128,56,     10,9,},
	{48,    56+32+8,10,9,},
	{48+128,56+32+8,10,9,},
	{48,    56+64+16,10,9,},
	{48+128,56+64+16,10,9,},

	{8*3,   176,14,9,},		// 下の３つ				// 14
	{40+8*3,176,14,9,},
	{224,   176,17,9,},



	{	48, 144,     23, 9,	},	// 使う時の選択肢		// 17
	{	48+12*8,144, 23, 9,	},
	{	48, 176,     23, 9	},
	{	48+12*8, 176,23, 9,	},

};

// 入れ替え用
static const BAG_CURSOR_INFO bag_insert_cursor_tbl[]={
	{48,    56,			20,9,},	// 真ん中の６つ
	{48+128,56,			20,9,},
	{48,    56+32+8,	20,9,},
	{48+128,56+32+8,	20,9,},
	{48,    56+64+16,	20,9,},
	{48+128,56+64+16,	20,9,},

	{8*3,   176,14,9,},		// 下の３つ				// 6
	{40+8*3,176,14,9,},
	{224,   176,17,9,},

};

// サブ用
static const BAG_CURSOR_INFO bag_sub_cursor_tbl[]={
	{ 136,   104, 29, 9, },
	{ 168,   104, 29, 9, },
	{ 200,   104, 29, 9, },
	{ 136,   160, 29, 9, },
	{ 168,   160, 29, 9, },
	{ 200,   160, 29, 9, },

	{ 160,   176, 17, 9, },
	{ 224,   176, 17, 9, },

};


//==============================================================================
/**
 * @brief   カーソルの位置＆形状制御
 *
 * @param   wk		バッグ画面ワーク
 * @param   pos		カーソル位置
 *
 * @retval  none
 */
//==============================================================================
void BgObj_CursorPosAppearSet( BAG_WORK *wk, int pos )
{

	CATS_ObjectPosSetCap_SubSurface( wk->cap[ACT_BAG_CURSOR],
							bag_cursor_tbl[pos].x,
							bag_cursor_tbl[pos].y,
							BAG_SUB_ACTOR_DISTANCE );
//	CATS_ObjectPosSetCap( wk->cap[ACT_BAG_CURSOR], bag_cursor_tbl[pos].x, bag_cursor_tbl[pos].y );
	CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_CURSOR], bag_cursor_tbl[pos].anim );
	CATS_ObjectPaletteSetCap( wk->cap[ACT_BAG_CURSOR], bag_cursor_tbl[pos].pal );
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_CURSOR ], ACT_ON );

}

//==============================================================================
/**
 * @brief   カーソル隠す
 *
 * @param   wk		バッグ画面ワーク
 *
 * @retval  none
 */
//==============================================================================
void BagObj_CursorDisappear( BAG_WORK *wk )
{
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_CURSOR ], ACT_OFF );

}


//==============================================================================
/**
 * @brief   どうぐ挿入カーソルの位置指定
 *
 * @param   wk		バッグ画面ワーク
 * @param   pos		カーソル位置
 *
 * @retval  none
 */
//==============================================================================
void BgObj_InsertCursorPosAppearSet( BAG_WORK *wk, int pos )
{
	GF_ASSERT( pos<9 );

	if( pos == 8 ){
		CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_CURSOR], bag_insert_cursor_tbl[pos].anim );
	}else{
		POCKET_DATA * pocket;
		int	lp;

		pocket = &wk->dat->p_data[wk->dat->p_now];

		lp = pocket->scr + pos;

		if( lp == wk->irekae_pos ){
			CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_CURSOR], 10 );
		}else if( lp >= pocket->max ){
			CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_CURSOR], 40 );
		}else{
			CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_CURSOR], 20 );
		}
	}

	CATS_ObjectPosSetCap_SubSurface(
		wk->cap[ACT_BAG_CURSOR],
		bag_insert_cursor_tbl[pos].x,
		bag_insert_cursor_tbl[pos].y,
		BAG_SUB_ACTOR_DISTANCE );
	CATS_ObjectPaletteSetCap( wk->cap[ACT_BAG_CURSOR],  bag_insert_cursor_tbl[pos].pal );
}

//==============================================================================
/**
 * @brief   捨てるモードのときのカーソル指定
 *
 * @param   wk		バッグ画面ワーク
 * @param   pos		カーソル位置
 *
 * @retval  none
 */
//==============================================================================
void BagObj_SubCursorPosAppearSet( BAG_WORK *wk, int pos )
{
	GF_ASSERT( pos<8 );

	CATS_ObjectPosSetCap_SubSurface( wk->cap[ACT_BAG_CURSOR],
										bag_sub_cursor_tbl[pos].x,
										bag_sub_cursor_tbl[pos].y,
										BAG_SUB_ACTOR_DISTANCE );
	CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_CURSOR], bag_sub_cursor_tbl[pos].anim );
	CATS_ObjectPaletteSetCap( wk->cap[ACT_BAG_CURSOR],  bag_sub_cursor_tbl[pos].pal );

}

//==============================================================================
/**
 * @brief   指定のポケットのみを明るくし、他は暗くする
 *
 * @param   wk		バッグ画面ワーク
 * @param   pos		カーソル位置
 *
 * @retval  none
 */
//==============================================================================
void BgObj_PocketPalSet( BAG_WORK *wk, int pos )
{
	int i;
	u16 *paladr;
	if(pos>7){
		return;
	}

	paladr = (u16*)wk->objPalPtr->pRawData;

	// 全部暗くする
//	for(i=0;i<BAG_POCKET_NUM;i++){
		GXS_LoadOBJPltt( &paladr[16*8], 0, 16*8*2);
//	}

	// 指定のボタンのみ明るくする
	GXS_LoadOBJPltt( &paladr[pos*16], pos*16*2, 16*2);

}

#define INSERT_TAG_MAX	( 6 )

//==============================================================================
/**
 * @brief   どうぐ移動用のタグ（O→）の表示制御
 *
 * @param   wk			バッグ画面ワーク
 * @param   num			表示しているどうぐの数
 * @param   target		移動対象の位置
 * @param   key			カーソルは表示するのかどうか
 *
 * @retval  none
 */
//==============================================================================
void BagObj_InsertTagSet( BAG_WORK *wk, int num, int target, int key )
{
	int i;

	// 個数指定が０だったらタグは全てオフ
	if( num==0 ){
		for(i=0;i<INSERT_TAG_MAX;i++){
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_INSERT_TAG1+i ], CATS_ENABLE_FALSE );
		}
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_INSERT_CURSOR ], CATS_ENABLE_FALSE );
	}else{

		// 移動先タグを全て表示する
		for(i=0;i<INSERT_TAG_MAX;i++){
			if(i<num){
				CATS_ObjectEnableCap( wk->cap[ ACT_BAG_INSERT_TAG1+i ], CATS_ENABLE_TRUE );
			}else{
				CATS_ObjectEnableCap( wk->cap[ ACT_BAG_INSERT_TAG1+i ], CATS_ENABLE_FALSE );
			}
		}

		// 移動元アイテムのタグは消す
		if(target>=0){
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_INSERT_TAG1+target ], CATS_ENABLE_FALSE );
		}
		// 移動用カーソルがでるかどうかはキー決定かタッチ決定かで変わる
		if(key){
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_INSERT_CURSOR ], CATS_ENABLE_FALSE );
		}
	}

}

//------------------------------------------------------------------
/**
 * @brief   ページ切り替えボタン表示の際の共通処理
 *
 * @param   wk		バッグ画面ワーク
 *
 * @retval  none
 */
//------------------------------------------------------------------
static void _page_button_on_func( BAG_WORK *wk )
{
	// ページ切り替えの必要が無い場合切り替えボタンを出さない
	if(wk->dat->p_data[wk->dat->p_now].max<=BAG_PAGE_ITEM_NUM){
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_UP_BUTTON ], ACT_OFF );
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_DOWN_BUTTON ], ACT_OFF );
	}else{
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_UP_BUTTON ], ACT_ON );
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_DOWN_BUTTON ], ACT_ON );
	}
// カーソルを暗くする版
#if 0
	// ページ切り替えボタンを表示させる
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_UP_BUTTON ], ACT_ON );
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_DOWN_BUTTON ], ACT_ON );

	// ページ切り替えの必要が無い場合は暗くする
	if(wk->dat->p_data[wk->dat->p_now].max<=BAG_PAGE_ITEM_NUM){
		CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_UP_BUTTON ], 32 );
		CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_DOWN_BUTTON ], 33 );
	}else{
		CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_UP_BUTTON ], 12 );
		CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_DOWN_BUTTON ], 13 );

	}
#endif
}


//------------------------------------------------------------------
/**
 * @brief   表示するどうぐの数にあわせてアイテムアイコンの表示も制御する
 *
 * @param   wk				バッグ画面ワーク
 * @param   p				ポケットデータのポインタ
 * @param   num				表示する個数
 * @param   icon_refresh	どうぐアイコンの再転送を行うか（0:無し 1:あり）
 *
 * @retval  none
 */
//------------------------------------------------------------------
void BagObj_ItemIconSet( BAG_WORK *wk, POCKET_DATA *p, int num, int icon_refresh )
{
	int i;

	for(i=0;i<BAG_PAGE_ITEM_NUM;i++){
		// どうぐアイコンを初期位置に戻す
		CATS_ObjectPosSetCap_SubSurface( wk->cap[ ACT_ITEMICON0+i ],
						ClactParamTbl[1+i].x,
						ClactParamTbl[1+i].y,
						BAG_SUB_ACTOR_DISTANCE );

		if(i<num){

			// ページ切り替え時はどうぐアイコン画像を転送する
			if(icon_refresh){
				BagItemIconChange( wk, i, wk->exist_item[p->scr+i] );
			}
			// 表示ON
			CATS_ObjectEnableCap( wk->cap[ ACT_ITEMICON0+i ], ACT_ON );

		}else{
			// 表示OFF
			CATS_ObjectEnableCap( wk->cap[ ACT_ITEMICON0+i ], ACT_OFF );
		}
	}

	// ページ送りボタン表示の際の共通処理
	_page_button_on_func( wk );
}


//==============================================================================
/**
 * @brief   どうぐ移動時のOBJ周り制御
 *
 * @param   wk		バッグ画面ワーク
 * @param   p		ポケット情報ポインタ
 * @param   only	移動を行うどうぐ（このアイコンだけ表示する）
 *
 * @retval  none
 */
//==============================================================================
void BagObj_ItemMoveIconSet( BAG_WORK *wk, POCKET_DATA *p, int only )
{
	int i;
	int icon=-1;

	if((only/6)*6 == p->scr){
		icon   = only%6;
	}

	for(i=0;i<BAG_PAGE_ITEM_NUM;i++){
		// どうぐアイコンを初期位置に戻す
		CATS_ObjectPosSetCap_SubSurface( wk->cap[ ACT_ITEMICON0+i ],
						ClactParamTbl[1+i].x,
						ClactParamTbl[1+i].y,
						BAG_SUB_ACTOR_DISTANCE );

		if(i==icon){
			// 表示ON
			CATS_ObjectEnableCap( wk->cap[ ACT_ITEMICON0+i ], ACT_ON );
		}else{
			// 表示OFF
			CATS_ObjectEnableCap( wk->cap[ ACT_ITEMICON0+i ], ACT_OFF );
		}
	}


	// ページ切り替えボタンを表示させる
	_page_button_on_func(wk);
}


//==============================================================================
/**
 * @brief   選択肢表示の制御
 *
 * @param   wk		バッグ画面ワーク
 * @param   tbl		メニューテーブル
 *
 * @retval  none
 */
//==============================================================================
void BagObj_SelectPlateAppear( BAG_WORK *wk, u8 *tbl )
{
	int i;
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_CURSOR ], ACT_ON );

	for(i=0;i<BAG_SELECT_MENU_PLATE_NUM;i++){
		if(tbl[i]!=255){
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_SELECT_PLATE0+i ], ACT_ON );
		}else{
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_SELECT_PLATE0+i ], ACT_OFF );
		}
	}

	// ページ切り替えボタンを隠す
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_UP_BUTTON ], ACT_OFF );
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_DOWN_BUTTON ], ACT_OFF );

}


//==============================================================================
/**
 * @brief   選択時プレート全部隠す
 *
 * @param   wk		バッグ画面ワーク
 *
 * @retval  none
 */
//==============================================================================
void BagObj_SelectPlateDisappear( BAG_WORK *wk )
{
	int i;
	for(i=0;i<BAG_SELECT_MENU_PLATE_NUM;i++){
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_SELECT_PLATE0+i ], ACT_OFF );
	}
}

#define SELECT_ITEM_ICON_POS_X	( 86 )
#define SELECT_ITEM_ICON_POS_Y	( 76 )
//==============================================================================
/**
 * @brief   選択肢移動制御
 *
 * @param   wk		バッグ画面ワーク
 * @param	select	選択位置
 *
 * @retval  none
 */
//==============================================================================
void BagObj_SelectItemMove( BAG_WORK *wk, int select )
{
	int i;
	for(i=0;i<BAG_PAGE_ITEM_NUM;i++){
		if(select!=i){
			// 対象以外のどうぐアイコンは表示オフ
			CATS_ObjectEnableCap( wk->cap[ ACT_ITEMICON0+i ], ACT_OFF );
		}else{
			// 選択したどうぐアイコンは中央のウインドウに移動
			CATS_ObjectPosSetCap_SubSurface( wk->cap[ ACT_ITEMICON0+i ],
							SELECT_ITEM_ICON_POS_X,
							SELECT_ITEM_ICON_POS_Y,
							BAG_SUB_ACTOR_DISTANCE );

		}
	}
}


//==============================================================================
/**
 * @brief   どうぐの所持数から数値入力ボタンの表示状態を判別する
 *
 * @param   max		どうぐの総数
 *
 * @retval  int		0:100以上	1:100以下	2:10以下
 */
//==============================================================================
int Bag_GetCountButtonPassive( int max )
{
	int ret=0;
	if(max<100){
		ret = 1;
	}
	if(max<10){
		ret = 2;
	}
	return ret;
}


// --------------------------------------
// 数値入力用のOBJオンオフテーブル
// --------------------------------------
static const NumActOnTbl[][6]={
	{	0,1,3,4,     	},
	{	0,1,2, 3,4,5,	},
};

static const NumActOnPat[][6]={
	{25,25,    27,27,},
	{25,25,25, 27,27,27,},
};

static const NumActNumTbl[]={
	4, 6,
};

static const NumActGlayTbl[][4]={
	{0,3,   },
	{0,1,3,4},
};

static const NumActGlayPat[][4]={
	{26,    28,},
	{26,26, 28,28,},
};

static const NumActGlayNumTbl[]={
	2,4,
};

//==============================================================================
/**
 * @brief   売る・捨てる用の数字指定ボタンを表示する
 *
 * @param   wk		work
 * @param   type	NUM_DIGI_2, NUM_DIGIT_3(２桁か３桁）bag_main.hに定義
 * @param   sel_max	指定できる最大
 *
 * @retval  none
 */
//==============================================================================
void BagObj_SelectCountAppear( BAG_WORK *wk, int type, int sel_max )
{
	int i,mode;

	if(type==NUM_DIGIT_2){
		if( sel_max > 99 ) sel_max = 99;
	}

	type -= NUM_DIGIT_2;


	// 2桁と3桁に対応してアクターの表示をONにする
	for(i=0;i<NumActNumTbl[type];i++){
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_NUM_UP0+NumActOnTbl[type][i] ], ACT_ON );
		CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_NUM_UP0+NumActOnTbl[type][i] ],
								   NumActOnPat[type][i] );
	}

	// 入力できない桁の場合はボタンをグレーにする
	if((mode=Bag_GetCountButtonPassive( sel_max ))!=0){
		if(type==0 && mode==2){
//			CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_NUM_UP0+ 0 ], 26 );
//			CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_NUM_UP0+ 3 ], 28 );
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_NUM_UP0+ 0 ], ACT_OFF );
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_NUM_UP0+ 3 ], ACT_OFF );
		}else if(type==1){
			for(i=0;i<NumActGlayNumTbl[mode-1];i++){
//				CATS_ObjectAnimeSeqSetCap( wk->cap[ ACT_BAG_NUM_UP0+ NumActGlayTbl[mode-1][i] ],
//										NumActGlayPat[mode-1][i] );
				CATS_ObjectEnableCap( wk->cap[ ACT_BAG_NUM_UP0+ NumActGlayTbl[mode-1][i] ], ACT_OFF );
			}
		}
	}

	// Ａ
	CATS_ObjectEnableCap( wk->cap[ACT_BAG_BUTTON_SELL_DOPOSIT], ACT_ON );
	CATS_ObjectAnimeFrameSetCap( wk->cap[ACT_BAG_BUTTON_SELL_DOPOSIT], 0 );
	CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_BUTTON_SELL_DOPOSIT], 37 );

	// Ｂ
	CATS_ObjectAnimeFrameSetCap( wk->cap[ACT_BAG_BACK_BUTTON], 0 );
	CATS_ObjectAnimeSeqSetCap( wk->cap[ACT_BAG_BACK_BUTTON], 39 );
}

//==============================================================================
/**
 * @brief   数字入力用のOBJをすべて隠す
 *
 * @param   wk		バッグ画面ワーク
 *
 * @retval  none
 */
//==============================================================================
void BagObj_SelectCountDisappear( BAG_WORK *wk )
{
	int i;

	for(i=0;i<BAG_ITEM_COUNT_BUTTON_NUM;i++){
		CATS_ObjectEnableCap( wk->cap[ ACT_BAG_NUM_UP0+i ], ACT_OFF );
	}

	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_BUTTON_SELL_DOPOSIT ], ACT_OFF );

}


//==============================================================================
/**
 * @brief   ポケット選択ボタンの表示ON/OFFを切り替える
 *
 * @param   wk		バッグ画面ワーク
 * @param   flag	ACT_ON / ACT_OFF
 *
 * @retval  none
 */
//==============================================================================
void BagObj_PocketSelectButtonOnOff( BAG_WORK *wk, int flag )
{
	int i;
	u8 pocket[BAG_POCKET_NUM];
	GF_ASSERT( flag==ACT_ON || flag == ACT_OFF );

	// p_dataに指定のタイプのどうぐデータ列があるか確認してからON/OFFを行う
	MI_CpuClear8( pocket, BAG_POCKET_NUM );
	for(i=0;i<BAG_POCKET_NUM;i++){
		GF_ASSERT( wk->dat->p_data[i].type < BAG_POCKET_NUM );
		if( wk->dat->p_data[i].item!=NULL ){
			pocket[wk->dat->p_data[i].type] = 1;
		}
	}

	// アクターON/OFFの反映
	for(i=0;i<BAG_POCKET_NUM;i++){
		if(pocket[i]){
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_BUTTON_1 + i ], flag );
		}else{
			CATS_ObjectEnableCap( wk->cap[ ACT_BAG_BUTTON_1 + i ], ACT_OFF );
		}
	}
}


//------------------------------------------------------------------
/**
 * @brief   「やめる」ボタン表示切替
 *
 * @param   wk		バッグ画面ワーク
 * @param   flag	TRUE = 表示, FALSE = 非表示
 *
 * @retval  none
 */
//------------------------------------------------------------------
void BagObj_CancelButtonOnOff( BAG_WORK *wk, int flag )
{
	CATS_ObjectEnableCap( wk->cap[ ACT_BAG_BACK_BUTTON ], flag );
}